package com.example.reference_book.util;

import com.example.reference_book.entity.School;
import com.example.reference_book.filter.SchoolFilter;
import com.example.reference_book.filter.schoolImpl.SchoolNameFilter;

import java.util.List;

public class SchoolSearchUtil {
    public static SchoolSearchUtil searchUtil;
    public static List<School> list;
    private SchoolSearchUtil (){

    }

    public void init(List<School> list) {
        this.list = list;
    }

    public static SchoolSearchUtil getSearchUtil() {
        if (searchUtil == null) {
            synchronized (SchoolSearchUtil.class) {
                if (searchUtil == null) {
                    searchUtil = new SchoolSearchUtil();
                }
            }
        }
        return searchUtil;
    }

    public List<School> searchByKey(String key){
        SchoolFilter filter = new SchoolNameFilter();
        return filter.getList(key,list);
    }
}
